import authority from '@/utils/authority'
import request from '@/utils/request'

export async function wxPhoneLogin({ phone, code }) {
  authority.clear()
  const { user, token, visitor } = await request({
    url: '/api/app/v1/login',
    method: 'post',
    data: {
      phone,
      code
    }
  })
  user.token = token
  user.visitor = visitor
  authority.set(user)
  // console.log(user)
  return user
}

// 获取code
export const getCode = (phone, type = 'login') => {
  return request({
    url: '/api/app/v1/phone/code',
    method: 'post',
    data: {
      type,
      phone
    }
  })
}

export function logout() {
  return Promise.resolve()
}

// 获取个人信息
export function getUserInfo() {
  return request(
    {
      url: '/api/app/v1/user'
    },
    {
      needLogin: true
    }
  )
}

export function editMydetail(data) {
  return request(
    {
      url: '/api/app/v1/user',
      method: 'post',
      data
    },
    {
      needLogin: true
    }
  )
}

// 我的收藏

export function collect() {
  return request(
    {
      url: '/api/hotel/v1/user/collection',
      method: 'get'
    },
    {
      needLogin: true
    }
  )
}
// 我的预约

export function reserve() {
  return request(
    {
      url: '/api/hotel/v1/user/reserve',
      method: 'get'
    },
    {
      needLogin: true
    }
  )
}
// 浏览历史

export function history() {
  return request(
    {
      url: '/api/hotel/v1/user/view',
      method: 'get'
    },
    {
      needLogin: true
    }
  )
}
